package application;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;

public abstract class Application
{
    public String title;
    public boolean running;
    public Dimension size;
    
    public Application()
    {
	this(0,0);
    }
    public Application(int w, int h)
    {
	title = "Application";
	size = new Dimension(w<=0?screenSize.width/2:w, h<=0?screenSize.height/2:h);
    }
    public void start()
    {
	new AppThread(this).run();
    }
    protected abstract void initializeApplication();
    protected abstract void init();
    protected abstract void run();
    protected abstract void update(double delta);
    protected abstract void redraw();
    protected abstract void render();
    
    public class AppThread implements Runnable
    {
	Application parent;
	public AppThread(Application app){parent = app;}
	@Override
	public void run() 
	{
	    parent.initializeApplication();
	    parent.run();
	}
    }
    public static int getScreenRefreshRate()
    {
	return refreshRate;
    }
    private static final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    private static final int refreshRate = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getRefreshRate();
}